//
//  SLGuideVC.m
//  SlockApp
//
//  Created by 凯朱 on 2024/7/9.
//

#import "SLGuideVC.h"
#import "SLLanguageSelectView.h"
#import "SLLoginVC.h"
#import "SLRegisterVC.h"
@interface SLGuideVC ()

@end

@implementation SLGuideVC

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setUpSubViews];
}

-(void)setUpSubViews{
    self.isHidenNaviBar = YES;
    self.view.backgroundColor = kHexColor(@"#0C0C0C");
    _registerBtn.btnStyle = 2;
    _loginBtn.btnStyle = 1;
    _tipLbl2.text = kLocalString(@"This app is designed for your HEXFORECE™ smart fingerprint padlock. Experience effortless security as you easily manage access for multiple users and locks, all in one place.");
    [self updateWithLang];
    [self loadBgImage];
    _changeBtn.hidden = YES;
    _changeIcon.hidden = YES;
}

-(void)loadBgImage{
    [ZKHttpManager getWithPath:@"/msl_user/StartPage/iOS" params:nil finished:^(BOOL isSuccessed, id  _Nonnull result, NSString * _Nonnull code, NSString * _Nonnull message) {
        if (isSuccessed) {
            NSString *url = kSTRING(result[@"result"][@"url"]);
            if (url.length > 0) {
                NSString *fullUrl = [url componentsSeparatedByString:@","][0];
                [self->_bgImage sd_setImageWithURL:[NSURL URLWithString:fullUrl] placeholderImage:[UIImage imageNamed:@"guide_bg"]];
            }
        }
    }];
}

- (IBAction)btnAction:(id)sender {
    if (sender == _changeBtn) {
        [self showLangSelectView];
    }else if (sender == _loginBtn){
        SLLoginVC *vc = [[SLLoginVC alloc] init];
        vc.step = 1;
        [self.navigationController pushViewController:vc animated:YES];
    }else if (sender == _registerBtn){
        SLRegisterVC *vc = [[SLRegisterVC alloc] init];
        vc.step = 1;
        [self.navigationController pushViewController:vc animated:YES];
    }
}


-(void)showLangSelectView{
    SLLanguageSelectView *langView = [SLLanguageSelectView viewFromXIB];
    [langView showWithAnmation:self.view];
    kWeakSelf(self);
    [langView setLangChangeBlock:^{
        [weakself updateWithLang];
    }];
}

-(void)updateWithLang{
    _tipLbl1.text = kLocalString(@"Welcome");
    _tipLbl2.text = kLocalString(@"This app is designed for HEXFORCE™ Padlock with Active Safety Protection & Dual-modulus Fingerprint Technolgy.");
    [_changeBtn setTitle:kLocalString(@"Change language") forState:UIControlStateNormal];
    [_registerBtn setTitle:kLocalString(@"Create new account") forState:UIControlStateNormal];
    [_loginBtn setTitle:kLocalString(@"Sign in") forState:UIControlStateNormal];
}

@end
